function courseList() {
    var _this = this;
    var page;
    _this.obj = null;
    _this.templateArr = [];
    _this.page_size = 10;

    // init
    _this.init = function(_page) {
        page = _page;
        _this.initTable();
        _this.initEvent();
    }

    _this.initTable = function() {
        var _this = this;
        var list_url = appPath + '/super/project/coursePackage/queryCourseList';
        /*
         * 分页
         * @param param_form 参数form id
         * @param list_url 请求链接
         * @param tbody_id 列表div id
         * @param page_id 分页id
         * @param pageNum 页数
         * @param pageSize 每页条数
         */
        page.init("queryCourseListForm", list_url, "pro_body", "pro_page", 1, 10);

        //初始化
        page.goPage(1);
        page.list = function (dataList) {
            //$("#checkAll").prop("checked",false);
            _this.obj = dataList;
            var len = dataList.length;
            var inner = "", item;
            // 组装数据
            for (var i = 0; i < len; i++) {

                item = dataList[i];
                inner += '<tr >';
                inner += '<td width="100">' + (i + 1) + '</td>';
                inner += '<td width="100"><input type=\"checkbox\" name="courseBox" value="' + item['course_id'] + '" data-id="' + item['course_id'] + '"></td>';
                inner += '<td >' + item['course_no'] + '</td>';
                inner += '<td width="480">' + item['course_name'] + '</td>';
                inner += '</tr>';
            }

            return inner;
        }



    }

    _this.initEvent = function () {
        //全选人员
        $("#all").click(function () {
            var flag=$("#all").prop("checked");
            $('#pro_body input[type="checkbox"]').prop("checked",flag);
        })

    }

    //批量删除
    $("#deleteBatch").click(function () {
        var courseIds = []
        $('#pro_body input:checked').each(function (i, e) {
            courseIds.push($(this).attr("data-id"));
        })
        if (courseIds.length == 0) {
            layer.msg("未选择课程");
            return;
        }
        layer.confirm("确定删除已选中的课程吗?", {
            icon: 3,
            btn: ["确认", "取消"]
        }, function () {
            $.ajax({
                url: appPath + '/super/project/coursePackage/deleteBatchCourse',
                async: false,
                type: 'post',
                data: {
                    'packageId': $("#packageId").val(), 	            // 项目总览id
                    'courseIds': courseIds.join(","), 		                    // 人员ids
                },
                success: function (data) {
                    var code = data['code'];
                    if (code == 10000) {
                        layer.alert('操作成功', {icon: 1, skin: 'layer-ext-moon'}, function (index) {
                            layer.close(index);
                            $("#all").prop("checked", false);
                            // 刷新项目人员
                            _this.initTable();
                        });
                    } else {
                        layer.alert('操作失敗', {icon: 2, skin: 'layer-ext-moon'});
                    }
                }
            });
        });

    })


    //返回
    $("#btnBack").click(function (){
        parent.page.refresh_cur_page();
        parent.layer.close(parent.layer.getFrameIndex(window.name));
    })

    //查询全部
    $("#searchAll").click(function (){
        $("#courseName").val("");
        _this.initTable();
    })

    //模糊查询searchText
    $("#searchText").click(function (){
        $("#courseName").val($.trim($("#courseName").val()));
        _this.initTable()
    })

     $("#relate").click(function (){
        // 调用选择培训课程的弹窗
        layer.open({
            type: 2,
            title: '选择课程',
            area: ['1200px', '80%'],		//弹出层大小
            scrollbar: false,				//false隐藏滑动块
            content: [appPath + '/super/project/coursePackage/enterSelectCourse?projectId=' + $("#projectId").val() + "&packageId=" + $("#packageId").val(), 'yes']
        });
    })

}

var courseList = new courseList();
